package thread.atomic;

import java.util.concurrent.atomic.AtomicIntegerArray;

/**
 * @author liweimin
 * @date 2021/4/29 16:32
 * @since
 */
public class AtomicIntegerArrayTest {
    public static void main(String[] args) {

        AtomicIntegerArray array = new AtomicIntegerArray(10);//初始化[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        System.out.println(array);

        array.set(2, 9090);
        System.out.println(array);
        System.out.println(array);

        System.out.println(array.getAndSet(2, 90));//返回原来元素，并设置新值
        System.out.println(array);

        System.out.println(array.addAndGet(2, 78));//先加再返回指定位置的值

        System.out.println(array.compareAndSet(2, 168, 123));//CAS
    }
}
